<?php
defined('IN_IA') or exit('Access Denied');
global $_W, $_GPC;
$uniacid = $_W['uniacid'];
$setting = $this->baseset($uniacid);
$jiangli = $setting['jiangli'] / 100;
$jiangli2 = $setting['jiangli2'] / 100;
$id = intval($_GPC['id']);
$diyjifen = intval($_GPC['diyjifen']);
load()->model('mc');
$settings = $this->module["config"];
if ($id > 0) {
	$poster = pdo_fetch("SELECT * FROM " . tablename('bsht_tbk_poster') . " WHERE uniacid = :uniacid order by id asc", array(':uniacid' => $_W['uniacid']));
	$showuser = pdo_fetch('SELECT * FROM ' . tablename($this->tableshow) . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
	$postuser1 = pdo_fetch('SELECT * FROM ' . tablename($this->tableuser) . ' WHERE uniacid = :uniacid AND openid = :openid', array(':uniacid' => $_W['uniacid'], ':openid' => $showuser['openid']));
	$postuser2 = pdo_fetch('SELECT * FROM ' . tablename($this->tableuser) . ' WHERE uniacid = :uniacid AND uid=:uid', array(':uniacid' => $_W['uniacid'], ':uid' => $postuser1['helpid']));
	if ($diyjifen && $diyjifen > 0) {
		$data_jfp = array();
		$data_jfp['jifen'] = $showuser['jifen'] + $diyjifen;
		$data_jfp['diyjifen'] = $diyjifen;
		pdo_update($this->tableshow, $data_jfp, array('id' => $id));
		$rejifen = $showuser['jifen'] + $diyjifen;
	} else {
		$rejifen = $showuser['jifen'];
	}
	$toopenid = $postuser1['openid'];
	$touid = mc_openid2uid($toopenid);
	$status = mc_credit_update($touid, 'credit1', $rejifen, array($touid, '发布晒单,奖励【' . $rejifen . '】积分'));
	$mcinfo = mc_fetch($touid);
	$mc_data = array('credit1' => $mcinfo['credit1'], 'credit2' => $mcinfo['credit2'],);
	pdo_update($this->tableuser, $mc_data, array('uid' => $touid, 'uniacid' => $_W['uniacid']));
	if ($poster['cscore'] > 0) {
		$touid1 = $postuser1['helpid'];
		if ($touid1 != 0) {
			$status1 = mc_credit_update($touid1, 'credit1', $rejifen * $jiangli, array($touid1, '被邀请人发布晒单,奖励【' . $rejifen * $jiangli . '】积分'));
			$mcinfo = mc_fetch($touid1);
			$mc_data = array('credit1' => $mcinfo['credit1'], 'credit2' => $mcinfo['credit2'],);
			pdo_update($this->tableuser, $mc_data, array('uid' => $touid1, 'uniacid' => $_W['uniacid']));
		}
	}
	if ($poster['pscore'] > 0) {
		$touid2 = $postuser2['helpid'];
		if ($touid2 != 0) {
			$status2 = mc_credit_update($touid2, 'credit1', $rejifen * $jiangli2, array($touid2, '被邀请人发布晒单,奖励【' . $rejifen * $jiangli2 . '】积分'));
			$mcinfo = mc_fetch($touid2);
			$mc_data = array('credit1' => $mcinfo['credit1'], 'credit2' => $mcinfo['credit2'],);
			pdo_update($this->tableuser, $mc_data, array('uid' => $touid2, 'uniacid' => $_W['uniacid']));
		}
	}
	$data = array();
	$data['status'] = 1;
	$data['queren'] = 1;
	pdo_update($this->tableshow, $data, array('id' => $id));
	$this->temp_ms_sh($showuser['openid'], $settings['sd_msname'] . "，奖励" . $rejifen . "积分", $settings['sd_mshead'], $settings['sd_msfoot'], $settings['sd_msdo'], $settings['sd_msmain']);
	message('操作成功.', referer());
}
message('非法访问.');